home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HyperLib 1997 Winter - Disc 1
/
HYPERLIB-1997-Winter-CD1.ISO.7z
/
HYPERLIB-1997-Winter-CD1.ISO
/
オンラインウェア
/
UTIL
/
Folder・Icon・Opener 1.0.1.sit
/
Folder•Icon•Opener 1.0.1
/
source code
/
sources
/
FIOpen.AE.c
next >
Wrap
Text File
|
1996-05-05
|
7KB
|
250 lines
/*
*--------------------------------------------------------------
* FIOpen.AE.c
*--------------------------------------------------------------
* Copyright ゥ Fumio Rokkaku, 1996
*--------------------------------------------------------------
*/
#pragma once
/* System Headers */
#include <Memory.h>
#include <AppleEvents.h>
#include <AERegistry.h>
#include <Aliases.h>
#include <OSUtils.h>
#include <Errors.h>
/* Project Headers */
#include "FIOpen.h"
/*
*--------------------------------------------------------------
* AppleEvent error kind messages
*--------------------------------------------------------------
*/
enum AEErrKinds {
/* message kinds */
iAEOpenApplication = 1,
iAEOpenDocuments,
iAEPrintDocuments,
iAEQuitApplication,
iAEOpenSelection,
iAESendMyOwnData,
iAEUnknownEvents,
/* error codes */
iAENotInstalled,
iAEInvalidConnect,
iAENotHandled,
iAEParameterErr,
iAEMemoryFull,
iAENotCoercion,
iAEWrongDataType,
iAEDecsNotFound,
iAEInvalDesc,
iAENoReplyComes,
iAETimeoutOccur,
iAEUnknownError,
errAENotInstalled = -1
};
/*
*--------------------------------------------------------------
* number of required AppleEvents
*--------------------------------------------------------------
*/
enum constAEHandlers {
kOpenApp = 0,
kOpenDoc,
kPrntDoc,
kQuitApp,
kNumOfAE
};
/*
*--------------------------------------------------------------
* AppleEvent handlers
*--------------------------------------------------------------
*/
pascal OSErr DoAEOpenApp(const AppleEvent *, AppleEvent *, long);
pascal OSErr DoAEOpenDoc(const AppleEvent *, AppleEvent *, long);
pascal OSErr DoAEPrntDoc(const AppleEvent *, AppleEvent *, long);
pascal OSErr DoAEQuitApp(const AppleEvent *, AppleEvent *, long);
/*
*--------------------------------------------------------------
* static fucntions only used within this source
*--------------------------------------------------------------
*/
static OSErr GotRequiredParams(const AppleEvent *);
/*
*--------------------------------------------------------------
* static global: AppleEvent Hander Universal ProcPtr
*--------------------------------------------------------------
*/
static AEEventHandlerUPP gMyAEUPPs[kNumOfAE];
/*
*--------------------------------------------------------------
* SetUpMyAppleEvent
*--------------------------------------------------------------
* set up Apple Event procedure
* if AppleEvent is not supported, do nothing in here
*--------------------------------------------------------------
*/
Boolean SetUpMyAppleEvent(void)
{
OSErr result = noErr;
gDragAndDrop = gDoubleClick = false;
/* make AppleEvent handler UPPs */
gMyAEUPPs[kOpenApp] = NewAEEventHandlerProc(DoAEOpenApp);
gMyAEUPPs[kOpenDoc] = NewAEEventHandlerProc(DoAEOpenDoc);
gMyAEUPPs[kPrntDoc] = NewAEEventHandlerProc(DoAEPrntDoc);
gMyAEUPPs[kQuitApp] = NewAEEventHandlerProc(DoAEQuitApp);
/* install required AppleEvents */
AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
gMyAEUPPs[kOpenApp], 0, false);
AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
gMyAEUPPs[kOpenDoc], 0, false);
AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
gMyAEUPPs[kPrntDoc], 0, false);
AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
gMyAEUPPs[kQuitApp], 0, false);
return (result == noErr);
}
/*
*--------------------------------------------------------------
* RemoveMyAppleEvent
*--------------------------------------------------------------
* delete AppleEvent handlers
*--------------------------------------------------------------
*/
void RemoveMyAppleEvent(void)
{
int i;
for (i = 0; i < kNumOfAE; ++i) {
if (gMyAEUPPs[i] != nil) {
DisposeRoutineDescriptor(gMyAEUPPs[i]);
}
}
}
/*
*--------------------------------------------------------------
* DoAEOpenApp
*--------------------------------------------------------------
* Open Application event: do nothing
*--------------------------------------------------------------
*/
pascal OSErr DoAEOpenApp(const AppleEvent *theAE, AppleEvent *reply, long refCon)
{
#pragma unused (theAE, reply, refCon)
gDoubleClick = true;
OpenAboutDialog();
return (noErr);
}
/*
*--------------------------------------------------------------
* DoAEOpenDoc
*--------------------------------------------------------------
* Open Document event: do open
*--------------------------------------------------------------
*/
pascal OSErr DoAEOpenDoc(const AppleEvent *theAE, AppleEvent *reply, long refCon)
{
#pragma unused (reply, refCon)
AEDescList fileSpecList = {typeNull, nil};
long listCount;
OSErr result;
result = AEGetParamDesc(theAE, keyDirectObject, typeAEList, &fileSpecList);
if (result == noErr) {
result = GotRequiredParams(theAE);
}
if (result == noErr) {
result = AECountItems(&fileSpecList, &listCount);
}
if (result == noErr) {
long index;
for (index = 1; index <= listCount; index++) {
AEKeyword keyword;
DescType itsType;
Size actualSize;
FSSpec gotSpec;
result = AEGetNthPtr(&fileSpecList, index, typeFSS, &keyword, &itsType,
(Ptr)&gotSpec, sizeof(FSSpec), &actualSize);
if (result == noErr) {
result = OpenFolderIcon(&gotSpec);
} else {
break;
}
}
}
AEDisposeDesc(&fileSpecList);
gDragAndDrop = true;
return (result);
}
/*
*--------------------------------------------------------------
* DoAEPrntDoc
*--------------------------------------------------------------
* Apple Event Print procedure
*--------------------------------------------------------------
*/
pascal OSErr DoAEPrntDoc(const AppleEvent *theAE, AppleEvent *reply, long refCon)
{
#pragma unused (theAE, reply, refCon)
gDone = true;
return (errAEEventNotHandled);
}
/*
*--------------------------------------------------------------
* DoAEQuitApp
*--------------------------------------------------------------
* Apple Event Quit procedure
*--------------------------------------------------------------
*/
pascal OSErr DoAEQuitApp(const AppleEvent *theAE, AppleEvent *reply, long refCon)
{
#pragma unused (theAE, reply, refCon)
gDone = true;
return (noErr);
}
/*
*--------------------------------------------------------------
* GotRequiredParams
*--------------------------------------------------------------
* Apple Event requred parameter parser
*--------------------------------------------------------------
*/
static OSErr GotRequiredParams(const AppleEvent *theAE)
{
DescType returnedType;
Size actualSize;
OSErr result;
result = AEGetAttributePtr(theAE, keyMissedKeywordAttr, typeWildCard,
&returnedType, nil, 0, &actualSize );
if (result == errAEDescNotFound) {
return (noErr);
} else if (result == noErr) {
return (errAEEventNotHandled);
}
return (result);
}